package com.manager
{
	import com.model.CarDataBase;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;

	public class CarXmlManager
	{
		private static var _carList:XMLList;
		private static var completeFunc:Function;
		
		public static function get carList():XMLList
		{
			return _carList;
		}
//		[Embed(source="xml/CarXml.xml")]
//		private static var xmlClass:Class;
		public static function loadCarXml(path:String,func:Function = null):void
		{
			completeFunc = func;
			var loader:URLLoader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.addEventListener(Event.COMPLETE,onComplete);
			loader.addEventListener(IOErrorEvent.IO_ERROR,onError);
			loader.load(new URLRequest(path));
			
//			var xml:XML = XML(new xmlClass());
//			_carList = xml.car;
//			CarDataBase.createCarDic();
//			if(completeFunc != null) completeFunc();
		}
		
		protected static function onError(e:IOErrorEvent):void
		{
			throw new Error("车辆配置表加载失败");
		}
		protected static function onComplete(e:Event):void
		{
			var xml:XML = XML((e.target as URLLoader).data);
			_carList = xml.car;
			CarDataBase.createCarDic();
			if(completeFunc != null) completeFunc();
		}
		
		
	}
}